# Contributor: Simon Frankenberger <simon-alpine@fraho.eu>
# Contributor: Terra <alpine-builder@tech.futurequest.net>
# Maintainer: Simon Frankenberger <simon-alpine@fraho.eu>
pkgname=nullmailer
pkgver=2.2
pkgrel=4
pkgdesc="Simple relay-only mail transport agent"
url="https://github.com/bruceg/nullmailer"
arch="all"
license="GPL-2.0-only"
subpackages="$pkgname-doc $pkgname-openrc"
makedepends="automake autoconf bash gnutls-dev"
checkdepends="daemontools ucspi-tcp6"
source="$pkgname-$pkgver.tar.gz::https://github.com/bruceg/nullmailer/archive/$pkgver.tar.gz
	fix-tests-catch-port.patch
	nullmailer-2.2-disable-dns-using-test.patch
	nullmailer-2.2-disable-smtp-auth-tests.patch
	nullmailer-2.2-fix-test-racecondition.patch

	nullmailer.initd
	adminaddr.conf
	defaultdomain.conf
	remotes.conf
	me.conf
	"
pkgusers="nullmailer"
pkggroups="nullmailer"
install="$pkgname.pre-install $pkgname.post-deinstall"
options="suid"

prepare() {
	default_prepare
	ash ./autogen.sh
}

build() {
	./configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--enable-tls
	make
}

check() {
	make check
}

package() {
	make DESTDIR=$pkgdir install
	install -Dm0755 "$srcdir/nullmailer.initd"   "$pkgdir/etc/init.d/nullmailer"
	install -Dm0644 "$srcdir/adminaddr.conf"     "$pkgdir/etc/nullmailer/adminaddr"
	install -Dm0644 "$srcdir/defaultdomain.conf" "$pkgdir/etc/nullmailer/defaultdomain"
	install -Dm0644 "$srcdir/remotes.conf"       "$pkgdir/etc/nullmailer/remotes"
	install -Dm0644 "$srcdir/me.conf"            "$pkgdir/etc/nullmailer/me"

	# ref: https://gitlab.alpinelinux.org/alpine/abuild/-/issues/10031
	rm -f "$pkgdir/var/spool/nullmailer/trigger"

	# fix permissions for nullmailer-queue so it can read / write the queue
	chown nullmailer "$pkgdir/usr/sbin/nullmailer-queue"
	chmod 4755 "$pkgdir/usr/sbin/nullmailer-queue"
}

sha512sums="
15c070edcf820ad13d8e0b250f73d75e45f592caa039e94fd717226fe09cd0ddc1f165388fab6234f57b340acc5127b54df14f35022858aab971b1f3d4e89e63  nullmailer-2.2.tar.gz
499666333703d6b4dfe9afa76f1d4a48ec7faa4a2ca9dbe8aee6737ce98dcf4509b281ebe2fd2ce0b32d3a91b807a8b2dcffe794b70cb5b3ccb10cb7eca713e4  fix-tests-catch-port.patch
d16592477612a716a8883ada1f18c34a4add81cfcfdda252705090e1f0b59f22a9bda9fe26bf950a78e21b9a69d20662825461669db72269280b7f82a1f8f8d9  nullmailer-2.2-disable-dns-using-test.patch
fc3bbcd8accd5a37b8292c6fb3e935ab1cd35d4a67bb224eadf48ff54b3b00508d6496e3d40c4546a966ce5dd6c297822a4e76a6b9e69d0ce47dd4e0e3883e47  nullmailer-2.2-disable-smtp-auth-tests.patch
10873e538dbc89e8899047e732515d30108b25fd0ff6bb2fc695f5790a94ac32629f41c470a2fec951357169fead36ee4512f543ad0e02c52f09799334b815c7  nullmailer-2.2-fix-test-racecondition.patch
5279c92a472e6f8b39003ec0edd67f5e6d8c23b285365f8a09e8456b38b947343ba35b82d2f0e44b222fa372428b1962bfa698082b89bab24701cd9599d98ab0  nullmailer.initd
6c32c2c49904b76bf01bdae13ecd382766ce9beeb2dadd9f127f0154d167eed5dc4ac00c4b5ec797757a35c3c4441652b8821a04ef44c82254cdac47e7ac9205  adminaddr.conf
a24ce5c1c2b335e26a1bcf565e2b3634f182ad22bef409c974589c70aa95fdb68441de12e59b51e8bd73ad3d6b6d87a3c285d476b61128ac3351db3a49866560  defaultdomain.conf
1c5a526f569b776f1862bc8b6ce00406ea76d79930fec81097518351660b93974a891058c85117773a401e4bfdbdac12149e01d8f643c76a90e8def9a42ba53d  remotes.conf
e71d3b3fe1b965c4645f0026768c2eecaadbc878348a20aaceb0fc8b3cbd794be820c620b20bdc3a270e3e8569df1077b1888141b699bd781f564e2b2671c65b  me.conf
"
